package thread2;

import java.util.concurrent.*;

public class CallableDemo implements Callable<Boolean> {

    @Override
    public Boolean call() {
        System.out.println("run callable thread");
        return true;
    }

    public static void main(String[] args) {
        CallableDemo callableDemo = new CallableDemo();
        CallableDemo callableDemo2 = new CallableDemo();
        CallableDemo callableDemo3 = new CallableDemo();
        // 创建线程池
        ExecutorService service = Executors.newFixedThreadPool(3);
        // 提交线程
        Future<Boolean> result = service.submit(callableDemo);
        Future<Boolean> result2 = service.submit(callableDemo2);
        Future<Boolean> result3 = service.submit(callableDemo3);
        try {
            // 获取执行结果
            System.out.println(result.get());
            System.out.println(result2.get());
            System.out.println(result3.get());
        } catch (InterruptedException | ExecutionException e) {
            e.printStackTrace();
        } finally {
            // 关闭线程池
            service.shutdown();
        }
    }
}
